#include "FileManager.h"

CFileManager::CFileManager(void){}
CFileManager::~CFileManager(void)
{
	for(vector<CPakFile*>::iterator pak = m_vectorOfFile.begin(); pak!=m_vectorOfFile.end(); pak++)
	{
		if(*pak != 0)
			delete (*pak);
	}
}

bool CFileManager::loadFile(const string& filename)
{
	CPakFile* newFile = new CPakFile();
	if(!newFile->loadFile(filename))
		return false;

	m_vectorOfFile.push_back(newFile);
	return true;
}

bool CFileManager::getPackedFile(const string& pakedFilename, char** buffer, int* size)
{
	//for every pack file in the vector
	for(vector<CPakFile*>::iterator pakFile = m_vectorOfFile.begin(); pakFile != m_vectorOfFile.end(); pakFile++)
	{
		//get the paked file
		if((*pakFile)->getFile(pakedFilename, buffer, size))
			return true;

	}
	return false;
}


bool CFileManager::closeFiles(void)
{
	for(vector<CPakFile*>::iterator i = m_vectorOfFile.begin(); i!=m_vectorOfFile.end(); i++)
		(*i)->closeFile();

	return true;
}
